<?php

namespace app\admin\controller\point;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
/**
 * Class Pointsource
 * @package app\admin\controller\system
 * @ControllerAnnotation(title="积分来源设置")
 */
class Pointsource extends AdminController
{

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model=(new \app\common\model\PointSource());
    }
    /**
     * @NodeAnotation(title="积分设置")
     */
    public function setting(){
        $row=$this->model->find(1);
        if ($this->request->isPost()) {
            $post = $this->request->post();
            $rule = [
                "aps_register"=>"require|integer",
                "aps_trade"=>"require|integer",
            ];
            $message = [
                "aps_register.require"=>"请填写整数积分数",
                "aps_trade.require"=>"请填写整数积分数",
            ];
            $this->validate($post, $rule,$message);
            try {
                $save = $this->model->where([['id','=',1]])->save($post);
            } catch (\Exception $e) {
                $this->error('保存失败:'.$e->getMessage());
            }
            $save ? $this->success('保存成功') : $this->error('保存失败');
        }
        $this->assign('row',$row);
        return $this->fetch();
    }
}